/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package drinkcounter.web.servlet;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import drinkcounter.DrinkCounterService;
import drinkcounter.model.Participant;
import drinkcounter.model.Party;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Toni
 */
@Singleton
public class AddDrinkServlet extends HttpServlet{

    @Inject private DrinkCounterService service;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String participantId = req.getParameter("id");
        service.addDrink(participantId);
        Participant participant = service.getParticipant(participantId);
        Party party = service.getParty(participant);
        resp.sendRedirect("/viewParty?id="+party.getId());
    }
}
